
// WARNING : USELESS PROGRAM, SINCE TOOL CANNOT HANDLE FLOATS !

object Pi {
    def main() : Unit = {
    	println(new PiCalc().CalcPi(500));
    }
}
class PiCalc {
    def CalcPi(Terms : Int) : Int = {
    	// And after writing "all" this, I notice that tool doesn't do floats...
    	var pi : Int;
    	var sign : Int;
    	var i : Int;
    	i = 0;
    	pi = 0; // Not really...
    	sign = 1;
    	while (i < Terms) {
    		// Simple Gregory-Leibniz (from wikipedia) : Pi = 4 * Sigma(k = 0->inf; (-1)^k / (2k+1) )
    		pi = pi + sign * (4 / (1+i*2));
    		// Invert sign (toolc unfortunately doesn't understand -1, so I wrote it as 0-1 (zero minus one))
    		sign = (0-1) * sign;
    		i = i + 1;
    	}
    	return pi;
    }
}
